"""
@name : 4.类的继承
@author : wenyao
@projectname: sanchuanglianxi
"""
# class Animal():
#     category = "animal"
#     count = 0
#
#     def __init__(self):
#         print("初始化annimal")
#         Animal.count += 1
#
#     def breath(self):
#         print("I can breath")
#
#     def eat(self):
#         print("I can  eat")
#
# class Person(Animal):
#     count = 0
#     category = "person"
#
#     def __init__(self):
#         print("初始化Person")
#         Person.count += 1
#
#     def eat(self):
#         print("person is eating")
#
# class Dog(Animal):
#     def eat(self):
#         print("dog is eating")
#
# class Pig(Animal):
#     count = 0
#     category = "pig"
#
#     def __init__(self):
#         super().__init__()  #python3支持
#         #python2  super必须要传参
#         #super(Pig, self).__init__()  #python2  python3 都支持
#         print("初始化pig")
#         Pig.count += 1
#         #super一般都是在子类中使用，去访问父类的东西的时候才会用到
#         #super 推荐用法
#
# #实例化对象
# animal = Animal()  #--》Animal.count +=1
# print("*******************")
# person = Person()  # -- >Person.count +=1
# print("*******************")
# dog = Dog()   #  --》 会去继承animal的 __init__  这个时候Animal.count +=1
# print("*******************")
# pig = Pig()  #  --->super访问父类的init  Animal.count +=1  , Pig.count  += 1
# print("*******************")
#
# #执行breath
# animal.breath()
# pig.breath()
# person.breath()
#
# #查看统计情况
# print("#"*30)
# print(Animal.count)
# print(Person.count)
# print(Pig.count)
#
# #重写父类方法
# animal.eat()
# dog.eat()
# person.eat()
# pig.eat()
#
# #注意类和实例的关系
# print("@"*30)
# print("isinstance(animal, Animal)",isinstance(animal,Animal))
# print("isinstance(pig, Pig)", isinstance(pig,Pig))
# print("isinstance(pig, Animal)",isinstance(pig, Animal))
# print("isinstance(animal, Pig)",isinstance(animal,Pig))

#自定义异常类
#try  except  raise  抛出自定义异常

class Listerror(Exception):
    # def __init__(self,list,messages):
    #     self.list = list
    #     self.messages = messages

    def __str__(self):
        print("test str")
        return "return test"

a = Listerror()
print(a)

try:
    s = input("请输入一个消息:")
    lst = list(input("请输入一个列表:"))
    if len(s) < 8 or len(lst) > 10:
        raise Listerror
    else:
        print("没有异常")
except Listerror as e:
    print("自定义异常",e)